//数码摇骰子
const int max = 8;
const int pinB = 2;
const int pinA = 3;
const int pinF = 4;
const int pinG = 5;
const int pinE = 6;
const int pinD = 7;
const int pinC = 8;
const int pinDP = 9;
int Pin[max] = {pinB,pinA,pinF,pinG,pinE,pinD,pinC,pinDP};


const int tiltSwitchPin = 13;
int sensorValue;
int lastTiltState = HIGH;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 100;

 int numbers[10][8] = {
  {0,0,0,1,0,0,0,1},//0
  {0,1,1,1,1,1,0,1},//1
  {0,0,1,0,0,0,1,1},//2
  {0,0,1,0,1,0,0,1},//3
  {0,1,0,0,1,1,0,1},//4
  {1,0,0,0,1,0,0,1},//5
  {1,0,0,0,0,0,0,1},//6
  {0,0,1,1,1,1,0,1},//7
  {0,0,0,0,0,0,0,1},//8
  {0,0,0,0,1,0,0,1},//9
  };
void setup() {
  // put your setup code here, to run once:
		Serial.begin(9600);
		for(int i = 0;i<max;i++){
		pinMode(Pin[i],OUTPUT);
		}
		pinMode(tiltSwitchPin,INPUT_PULLUP);
}

void loop() {
  // put your main code here, to run repeatedly:
unsigned long currentTime = millis();
int sensorValue = digitalRead(tiltSwitchPin);
if(sensorValue !=lastTiltState && (currentTime-lastDebounceTime)>debounceDelay){
		int randomNumber = random(0,10);
		displayNumber(randomNumber);
		lastTiltState = sensorValue;
		lastDebounceTime = currentTime;
		}
}
void displayNumber(int number){
		for(int i = 0;i<max;i++){
		digitalWrite(Pin[i],numbers[number][i]);
		}
}
